package com.restaurantonlineorder.seller.configure;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

@Configuration
@Slf4j
public class JacksonConfig {
    
    @Bean
    public Converter<String, LocalDateTime> localDateTimeConverter() {
        return new Converter<String, LocalDateTime>() {
            @Override
            public LocalDateTime convert(String s) {
                return ZonedDateTime.parse(s, DateTimeFormatter.ISO_ZONED_DATE_TIME)
                        .withZoneSameInstant(ZoneId.ofOffset("UTC", ZoneOffset.ofHours(8))).toLocalDateTime();
            }
        };
    }

    @Bean
    public Converter<String, ZonedDateTime> zonedDateTimeConverter() {
        return new Converter<String, ZonedDateTime>() {
            @Override
            public ZonedDateTime convert(String s) {
                return ZonedDateTime.parse(s, DateTimeFormatter.ISO_ZONED_DATE_TIME);
            }
        };
    }

}
